package com.hevs.samplewebapp.client.bean;

/**
 * Enum Class of Type
 * <p>The goal is to map indexes to name for the type of medical data</p>
 * 
 * @author Matthias Hurni
 * @date 26.03.2012
 */
public enum Type
{
        /**
         * Blood sugar
         */
        BLOODSUGAR(0,"Blood sugar"),
        
        /**
         * Insuline: Humalog
         */
        HUMALOG(11,"Humalog"),
        
        /**
         * Insuline: Novorapid
         */
        NOVORAPID(12,"Novorapid"),
        
        /**
         * Weight
         */
        WEIGHT(2,"Weight"),
        
        /**
         * Blood pressure: Diastolic
         */
        DIASTOLIC(3,"Blood presure diastolic"),
        
        /**
         * Blood pressure: Systolic
         */
        SYSTOLIC(4,"Blood presure systolic"),

        /**
         * Pulse Rate
         */
        PULSERATE(5,"Pulse rate");

        /**
         * Insuline Type
         */
        public static final int INSULINE_INDEX=11;
        
        /**
         * numerical representation of the type
         */
        private int level;
        
        /**
         * name of the type
         */
        private final String name;
        
    	// ----------------------------------------------------------------------------
    	// Constructor
    	// ----------------------------------------------------------------------------
        
        /**
         * Constructor of the type to map a name to a number
         * @param level
         * 	numerical representation of the type
         * @param name
         * 	name of the type
         */
        private Type(int level,String name)
        {
                this.level=level;
                this.name=name;
        }

    	// ----------------------------------------------------------------------------
    	// Methods
    	// ----------------------------------------------------------------------------

        /**
         * Returns the integer value of this level
         */
        public int getLevel()
        {
                return level;
        }

        /**
         * Returns the name of this level
         */
        public String getName() {
                return name;
        }
        
        /**
         * Returns the size of the enum
         */
        public static int getSize()
        {
                return Type.values().length;
        }

        public String toString()
        {
                return name;
        }
        
        /**
         * Returns the index of the enum (used for Lists)
         * @param val
         * 	
         * @return Index
         */
        public static int getIndex(int val)
        {
                switch(val)
                {
                        case 0:
                                return 0;
                        case 11:
                                return 1;
                        case 12:
                                return 2;
                        case 2:
                                return 3;
                        case 3:
                                return 4;
                        case 4:
                                return 5;
                        case 5:
                                        return 6;
                        default:
                                return -1;
                }       
        }

        /**
         * Get the enum with an index (used for Lists)
         * @param val
         * @return Type
         */
        public static Type getFromInt(int val)
        {
                switch(val)
                {
                        case 0: 
                                return BLOODSUGAR;
                        case 1:
                                return HUMALOG;
                        case 2:
                                return NOVORAPID;
                        case 3:
                                return WEIGHT;
                        case 4:
                                return DIASTOLIC;
                        case 5:
                                return SYSTOLIC;
                        case 6:
                                return PULSERATE;
                        default:
                                return null;
                }
        }
        
        /**
         * Get the enum's value
         * @param val
         * @return Type
         */
        public static Type getFromVal(int val)
        {
                switch(val)
                {
                        case 0:
                                return BLOODSUGAR;
                        case 11:
                                return HUMALOG;
                        case 12:
                                return NOVORAPID;
                        case 2:
                                return WEIGHT;
                        case 3:
                                return DIASTOLIC;
                        case 4:
                                return SYSTOLIC;
                        case 5:
                                return PULSERATE;
                        default:
                                return null;
                }
        }
}